package com.kgc.goods.goodsweb.controller;

import com.kgc.goods.entity.Goods;
import com.kgc.goods.service.GoodsService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class GoodController {
    @Reference
    GoodsService goodsService;

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<Goods> selectAll(@RequestParam(value = "district",defaultValue = "0")Integer district){
        List<Goods> goodsList = goodsService.selectAll(district);
        return goodsList;
    }
    @RequestMapping("/selectAllById")
    @ResponseBody
    public Goods selectById(Integer id){
        Goods goods = goodsService.selectById(id);
        return goods;
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(@RequestBody Goods goods){
        Map<String,Object> map=new HashMap<>();
        int i = goodsService.updateGoods(goods);
        if (i>0){
            map.put("result","success");
            return map;
        }else{
            map.put("error","down");
            return map;
        }
    }
    }

